package com.ukao.steward.adapter;

import android.content.Context;
import android.content.res.Resources;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.ukao.steward.R;
import com.ukao.steward.base.ListBaseAdapter;
import com.ukao.steward.base.SuperViewHolder;
import com.ukao.steward.bean.Coupons;
import com.ukao.steward.bean.StringBean;
import com.ukao.steward.bean.WaitingOrderBean;
import com.ukao.steward.util.CheckUtils;
import com.ukao.steward.util.DecimalUtil;
import com.ukao.steward.util.DensityUtils;
import com.ukao.steward.util.MyDateUtils;

import java.util.List;



/**
 * 优惠券
 */

public class CouponsAdapter extends ListBaseAdapter<Coupons> {


    public CouponsAdapter(Context context, List<Coupons> mDataList) {
        super(context, mDataList);
    }
    @Override
    public int getLayoutId() {
        return R.layout.coupons_items;
    }



    @Override
    public void onBindItemHolder(SuperViewHolder viewHolder, final int position) {

        Resources mResources = mContext.getResources();

        LinearLayout  moueyLayout=viewHolder.getView(R.id.mouey_layout);
        TextView  credits=viewHolder.getView(R.id.coupons_credits_tv);
        TextView availableCondition= viewHolder.getView(R.id.coupons_available_condition_tv);
        TextView  name=viewHolder.getView(R.id.coupons_name_tv);
        TextView   type=viewHolder.getView(R.id.coupons_type_tv);
        TextView   validDate= viewHolder.getView(R.id.coupons_valid_date_tv);
        LinearLayout iamgeBackgroud=viewHolder.getView(R.id.iamge_backgroud);
        ImageView iamgePastdue=viewHolder.getView(R.id.iamge_pastdue);
        TextView   mouey= viewHolder.getView(R.id.mouey);
        ImageView paySelect=viewHolder.getView(R.id.pay_select);
        ViewGroup.LayoutParams mParams = moueyLayout.getLayoutParams();
        mParams.width= (int) ((DensityUtils.getScreenW()-DensityUtils.dip2px(20))*0.37);
        moueyLayout.setLayoutParams(mParams);
        Coupons coupons = mDataList.get(position);
        validDate.setText(MyDateUtils.formatDate(coupons.getTimeStart())+"至"+MyDateUtils.formatDate(coupons.getTimeEnd()));/*时间*/
        type. setText(CheckUtils.isEmptyString(coupons.getCouponRuleName()));
        name.setText(coupons.getName());/*标题*/
        availableCondition.setText(coupons.fullAmount == 0 ? "无限制" : "满" + CheckUtils.isEmptyNumber(coupons.getFullAmount()) + "可使用");
        credits.setText(CheckUtils.isEmptyNumber(coupons.getAmount()));




            if (coupons.getEnableUse()||coupons.isCheck()){/*是否可用*/
                viewHolder.itemView.setAlpha(1f);
                credits.setTextColor(mResources.getColor(R.color.orange));
                mouey.setTextColor(mResources.getColor(R.color.orange));
                availableCondition .setTextColor(mResources.getColor(R.color.black_gray));
                name.setTextColor(mResources.getColor(R.color.black));
                type. setTextColor(mResources.getColor(R.color.black_gray));
                validDate.setTextColor(mResources.getColor(R.color.black_gray));//coupons_valid_date
                iamgeBackgroud.setBackgroundResource(R.drawable.coupons_valid);
                iamgePastdue.setVisibility(View.GONE);
                paySelect.setVisibility(coupons.isCheck() ? View.VISIBLE : View.GONE);

            }else  {
                paySelect.setVisibility(View.GONE);
                viewHolder.itemView.setAlpha(0.5f);
            }





}}
